package thead;

/**
 * @ProjectName: interview
 * @Package: thead
 * @ClassName: TicketWindow
 * @Author: chenmengqi
 * @Description:
 * @Date: 2020/4/1 3:11 下午
 * @Version: 1.0
 */
public class TicketWindow extends Thread {
    //柜台名称
    private final String name;
    //最多受理50笔业务
    private static final int MAX = 50;
    private int index = 1;

    public TicketWindow(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        while (index <= MAX) {
            System.out.println("柜台:" + name + "当前的号码是:" + (index++));
        }
    }

    /**
     * 每个线程使用的是自己独立的对象，不存在资源共享
     *
     * @param args
     */

    public static void main(String[] args) {
        TicketWindow ticketWindow1 = new TicketWindow("出号机1");
        ticketWindow1.start();
        TicketWindow ticketWindow2 = new TicketWindow("出号机2");
        ticketWindow2.start();
        TicketWindow ticketWindow3 = new TicketWindow("出号机3");
        ticketWindow3.start();
        TicketWindow ticketWindow4 = new TicketWindow("出号机4");
        ticketWindow4.start();
    }
}
